<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>魔方轮播</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f0f0f0;
            perspective: 1000px;
        }

        .cube-carousel {
            width: 500px;
            height: 500px;
            position: relative;
            transform-style: preserve-3d;
        }

        .cube-container {
            width: 100%;
            height: 100%;
            position: relative;
            transform-style: preserve-3d;
            transition: transform 1s ease;
        }

        .cube-face {
            position: absolute;
            width: 100%;
            height: 100%;
            overflow: hidden;
            backface-visibility: hidden;
        }

        .cube-face img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .cube-face:nth-child(1) { transform: translateZ(250px); }
        .cube-face:nth-child(2) { transform: rotateY(90deg) translateZ(250px); }
        .cube-face:nth-child(3) { transform: rotateY(180deg) translateZ(250px); }
        .cube-face:nth-child(4) { transform: rotateY(-90deg) translateZ(250px); }
        .cube-face:nth-child(5) { transform: rotateX(90deg) translateZ(250px); }

        .controls {
            position: fixed;
            bottom: 20px;
            display: flex;
            gap: 10px;
            z-index: 100;
        }

        .control-btn {
            padding: 10px 20px;
            background: #333;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            transition: background 0.3s;
        }

        .control-btn:hover {
            background: #555;
        }
    </style>
</head>
<body>
    <div class="cube-carousel">
        <div class="cube-container">
            <div class="cube-face"><img src="../img/1 (1).png" alt="Image 1"></div>
            <div class="cube-face"><img src="../img/1 (2).png" alt="Image 2"></div>
            <div class="cube-face"><img src="../img/1 (3).png" alt="Image 3"></div>
            <div class="cube-face"><img src="../img/1 (4).png" alt="Image 4"></div>
            <div class="cube-face"><img src="../img/1 (5).png" alt="Image 5"></div>
        </div>
    </div>
    <div class="controls">
        <button class="control-btn prev">上一张</button>
        <button class="control-btn next">下一张</button>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const container = document.querySelector('.cube-container');
            const prevBtn = document.querySelector('.prev');
            const nextBtn = document.querySelector('.next');
            
            let currentIndex = 0;
            const totalFaces = 5;
            let isAnimating = false;

            function updateCarousel() {
                if (isAnimating) return;
                isAnimating = true;

                const rotationY = currentIndex * -90;
                container.style.transform = `rotateY(${rotationY}deg)`;

                setTimeout(() => {
                    isAnimating = false;
                }, 1000);
            }

            prevBtn.addEventListener('click', () => {
                if (!isAnimating) {
                    currentIndex = (currentIndex - 1 + totalFaces) % totalFaces;
                    updateCarousel();
                }
            });

            nextBtn.addEventListener('click', () => {
                if (!isAnimating) {
                    currentIndex = (currentIndex + 1) % totalFaces;
                    updateCarousel();
                }
            });

            // Initialize carousel
            updateCarousel();

            // Auto play
            setInterval(() => {
                if (!isAnimating) {
                    currentIndex = (currentIndex + 1) % totalFaces;
                    updateCarousel();
                }
            }, 3000);

            // Add mouse drag support
            let isDragging = false;
            let startX = 0;
            let startRotation = 0;

            container.addEventListener('mousedown', (e) => {
                if (!isAnimating) {
                    isDragging = true;
                    startX = e.clientX;
                    startRotation = currentIndex * -90;
                }
            });

            document.addEventListener('mousemove', (e) => {
                if (isDragging && !isAnimating) {
                    const deltaX = e.clientX - startX;
                    const rotation = startRotation + deltaX * 0.5;
                    container.style.transform = `rotateY(${rotation}deg)`;
                }
            });

            document.addEventListener('mouseup', () => {
                if (isDragging) {
                    isDragging = false;
                    const deltaX = event.clientX - startX;
                    if (Math.abs(deltaX) > 50) {
                        currentIndex = deltaX > 0 ? 
                            (currentIndex - 1 + totalFaces) % totalFaces : 
                            (currentIndex + 1) % totalFaces;
                    }
                    updateCarousel();
                }
            });
        });
    </script>
</body>
</html>